package com.base.Queue;

import com.base.helper.WebHelper;
import lombok.extern.log4j.Log4j;
import net.sf.json.JSONObject;

import java.util.concurrent.TimeUnit;

@Log4j
public class SbdCallBackWorker implements Runnable {
    private String URL; //回调的CallBack
    private JSONObject jsonObject;
    private int time;

    public SbdCallBackWorker(String URL, JSONObject jsonObject) {
        this.URL = URL;
        this.jsonObject = jsonObject;
        this.time =3;
    }

    public SbdCallBackWorker(String URL,JSONObject jsonObject,int time){
        this.URL = URL;
        this.jsonObject = jsonObject;
        this.time =time;
    }
    @Override
    public void run() {
       String result= WebHelper.doBodyPost(URL, jsonObject);
       if (result == null && time>0){
           time --;
           SbdCallBackWorker worker=new SbdCallBackWorker(URL,jsonObject,time);
           DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
           manager.put(worker, 3, TimeUnit.MILLISECONDS);
       }
        log.warn("[话单通知]"+URL+":"+result);
    }
}
